home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / msdos / zbyte11.zip / 0-BYTE.C next >
C/C++ Source or Header  |  1993-11-27  |  3KB  |  111 lines

  1. /* 0-byte.c */
  2.  
  3. /*
  4.     DESCRIPTION:
  5.     Accepts a DIR listing from Standard Input, and produces a 0-byte
  6.     length file for each file listed in the DIR listing.
  7.  
  8.     Subidirectories are ignored.
  9.  
  10.     USAGE:
  11.  
  12.     DIR \target\subdirectory | 0-BYTE > capture.cap
  13.  
  14.     The 0-byte-length files will be created in the current subdirectory.
  15.     0-byte will not overwrite existing files. Check CAPTURE.CAP for
  16.     the names of duplicate files found.
  17.  
  18.     dap@kandy.com  11/26/93
  19. */
  20.  
  21. /*
  22.     HISTORY:
  23.     If you find a bug, report it. Otherwise it probably won't get fixed.
  24.  
  25.     11/27/93 v1.1 Sets date and time of 0-byte file to reflect date
  26.          and time of original file.
  27.     11/26/93 v1.0 Initial release. First (and hopefully last) version.
  28. */
  29.  
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <dos.h>
  35. #include <errno.h>
  36.  
  37. main()
  38. {
  39.   unsigned  dos_handle;
  40.   unsigned  mo, da, yr, hr, mn;
  41.   unsigned  dat, tim;
  42.   char      *k;
  43.   char      buf[512];
  44.  
  45.   fprintf(stderr, "0-BYTE v1.1 <dap@kandy.com>\n");
  46.   fprintf(stderr, "Last compiled on %s at %s\n\n", __DATE__, __TIME__);
  47.  
  48.   while((fgets(buf, 511, stdin))!=NULL)
  49.   {
  50.     if((strstr(buf, "<DIR>"))!=NULL)
  51.       continue;
  52.  
  53.     if(*buf==' ' || *buf=='\n')
  54.       continue;
  55.  
  56.     mo=(unsigned)atoi(buf+23);
  57.     da=(unsigned)atoi(buf+26);
  58.     yr=(unsigned)(atoi(buf+29)-80);
  59.     dat = (yr << 9) | (mo << 5) | da;
  60.  
  61.     hr=(unsigned)atoi(buf+33);
  62.     if(*(buf+38)=='p')
  63.       hr+=12;
  64.     mn=(unsigned)atoi(buf+36);
  65.     tim = (hr << 11) | (mn << 5);
  66.  
  67.     *(buf+12)='\0';
  68.  
  69.     k=strchr(buf, ' ');
  70.     *k='.';
  71.  
  72.     k++;
  73.     while(*k==' ')
  74.       strcpy(k, k+1);
  75.  
  76.     if((k=strchr(buf, ' '))!=NULL)
  77.       *k='\0';
  78.  
  79.     if(!strcmp(buf, "...") || !strcmp(buf, ".."))
  80.       continue;
  81.  
  82.     if(_dos_creatnew(buf, 0, &dos_handle))
  83.     {
  84.       if(errno==EACCES)
  85.     fprintf(stderr, "ERROR: %c%c%c%s: %s\n", (char)7, (char)7, (char)7,
  86.         buf, "Permission denied");
  87.       else if(errno==EEXIST)
  88.       {
  89.     fputc(7, stderr);
  90.     printf("%s EXISTS and will not be overwritten!\n", buf);
  91.       }
  92.       else if(errno==EMFILE)
  93.     fprintf(stderr, "ERROR: %c%c%c%s: %s\n", (char)7, (char)7, (char)7,
  94.         buf, "Too many open files");
  95.       else if(errno==ENOENT)
  96.     fprintf(stderr, "ERROR: %c%c%c%s: %s\n", (char)7, (char)7, (char)7,
  97.         buf, "No such file or directory");
  98.       else
  99.     fprintf(stderr, "ERROR: %c%c%c%s: %s\n", (char)7, (char)7, (char)7,
  100.         buf, "Unknown error");
  101.     }
  102.     else
  103.     {
  104.       _dos_setftime(dos_handle, dat, tim);
  105.       printf("%s\n", buf);
  106.       _dos_close(dos_handle);
  107.     }
  108.   }
  109.   exit(0);
  110. }
  111.